﻿using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;

namespace Devonline.Identity;

/// <summary>
/// Identity service bearer access token options
/// </summary>
public class IdentityBearerOptions : JwtBearerOptions
{
    /// <summary>
    /// 过期时间
    /// </summary>
    public int ExpiresIn { get; set; } = AppSettings.UNIT_SECONDS_AN_HOUR;
    /// <summary>
    /// SecurityKey that is to be used for signature validation.
    /// </summary>
    public string? IssuerSigningKey { get; set; }

    /// <summary>
    /// 自配置方法
    /// </summary>
    /// <param name="options"></param>
    public void Configure()
    {
        ArgumentNullException.ThrowIfNullOrWhiteSpace(IssuerSigningKey);
        TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(IssuerSigningKey));
    }
}